package com.gupao.javavip.netty.push.client.processor.handler;

import com.gupao.javavip.netty.push.client.connection.RetryConnector;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.apachecommons.CommonsLog;

/**
 * 断开重连
 */
@CommonsLog
public class ReconnectHandler extends ChannelInboundHandlerAdapter {
    private RetryConnector connector;

    public ReconnectHandler(RetryConnector connector) {
        this.connector = connector;
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        if (connector.getRetries() == 0) {
            ctx.close();
        }
        connector.reConnect(ctx);
        ctx.fireChannelInactive();
    }
}
